/**
 */
;
(function(){
'use strict';

	var app = angular.module('fwa.mainApp');
	app.controller('WarningAuditQueryCtrl', ['$scope','$modal','$state', 
	                                  '$stateParams','WarningAddService','BaseURL','Modal',
	    function ($scope,$modal,$state,$stateParams,WarningAddService,baseUrl,Modal) {
		$scope.serv = WarningAddService;
		var warnNo = $stateParams.warnNo;
		var actNo = $stateParams.actNo;
		WarningAddService.getHcpmsWarning({warnNo:warnNo})
		.success(function(res){
				$scope.warningFrom=res.warnInfo;
                $scope.warnScreenList=res.warnScreenList;
                $scope.warningMedical=res.warnMedicalList;
        		$scope.warningStaff=res.warnStaffList;
        		$scope.warningInsurance=res.warnInsuranceList;
        		if(linkResult(actNo)){//加载tab页
        			linkResultPage();
        		}
	     });
		// ng-controller = "WarningExamineResultCtrl"
		// ng-controller = "WarningApprovalResultCtrl"
		var codeType=['COMPLAIN_TYPE','SOURCE_TYPE','PROCESS_TYPE'];
//		$scope.screenUrl='views/hcpms/warning/warnView/warningViewScreen_view.html';
		$scope.warnBaseUrl='views/hcpms/warning/warnView/warningViewBase_view.html';
		$scope.tabs=[{label:'医疗机构',id:0,url:'views/hcpms/warning/warnView/warningViewMedical_view.html'},
		             {label:'医护人员',id:1,url:'views/hcpms/warning/warnView/warningViewStaff_view.html'},
		             {label:'参保人员',id:2,url:'views/hcpms/warning/warnView/warningViewInsurance_view.html'}];
		var pageOne = {label:'网上筛查',id:0,url:baseUrl+'views/hcpms/warning/warnView/warningViewScreen_view.html'};
		var pageTwo = {label:'自查结果',id:1,url:baseUrl+'views/hcpms/warning/warnView/warningEditCheckResult_view.html'};
		var pageThree = {label:'结果评估',id:2,url:baseUrl+'views/hcpms/warning/warnView/warningResultQuery_view.html'};
		var pageFour = {label:'复审意见',id:3,url:baseUrl+'views/hcpms/warning/warnView/warningQueryAudit_view.html'};
		var pageFive= {label:'审批意见',id:4,url:baseUrl+'views/hcpms/warning/warnView/warningQueryExamine_view.html'};
		$scope.tabResults = [];
		$scope.selectedTab = $scope.tabs[0];
		$scope.selectedResultTab = $scope.tabResults[0];
		$scope.currentTabIndex = 0;
		$scope.currentResultTabIndex = 0;
		$scope.complainModeList=[];
		$scope.setComplainMode = function(codeNo){
			angular.forEach($scope.complainModeList,function(data,index){
				   if(data.codeNo==codeNo&&data.checked === false){
					   data.checked = true;
				   }else{
					   data.checked = false;
				   }
			   });
        }
		$scope.tabClick = function(tab) {
			$scope.selectedTab = tab;
			$scope.currentTabIndex=tab.id;
		}
		$scope.tabResultClick = function(tab) {
			$scope.selectedResultTab = tab;
			$scope.currentResultTabIndex=tab.id;
		}
		
		 var linkResult = function (actNo){
	   $scope.isFlatOne = false;
	   $scope.isFlatTwo = false;
	   $scope.isFlatThree = false;
	   $scope.isFlatFour = false;
	   $scope.isFlatFive = false;
	   if(actNo == 'N2014001'
		   		|| actNo == 'N2014002'
		   		|| actNo == 'N2014003'
		   		|| actNo == 'N2014004'
		   		|| actNo == 'N2014005'){//1tab
		   $scope.isFlatOne = true; 
	   }else if(actNo == 'N2014006'){//2tab
		   $scope.isFlatOne = true;
		   $scope.isFlatTwo = true; 
	   }else if(actNo == 'N2014007'){//3tab
		   $scope.isFlatOne = true;
		   $scope.isFlatTwo = true;
		   $scope.isFlatThree = true;
	   }else if(actNo == 'N2014008'){//4tab
		   $scope.isFlatOne = true;
		   $scope.isFlatTwo = true;
		   $scope.isFlatThree = true;
		   $scope.isFlatFour = true;
	   }else if(actNo == 'N2014009'){//5tab
		   $scope.isFlatOne = true;
		   $scope.isFlatTwo = true;
		   $scope.isFlatThree = true;
		   $scope.isFlatFour = true;
		   $scope.isFlatFive = true;
	   }
	   return true;
  }
	 var linkResultPage = function(){
			if($scope.isFlatOne){
//				$scope.tabOneController = "";
				$scope.tabResults.push(pageOne);
				$scope.isNumOne = 0;
				if($scope.isFlatTwo){
					$scope.tabTwoController = "";
					$scope.tabResults.push(pageTwo);
					$scope.isNumTwo = 1;
					if($scope.isFlatThree){
						$scope.tabThreeController = "WarningResultQueryCtrl";
						$scope.tabResults.push(pageThree);
						$scope.isNumThree = 2;
						if($scope.isFlatFour){
							$scope.tabFourController = "WarningExamineResultCtrl";
							$scope.tabResults.push(pageFour);
							$scope.isNumFour = 3;
							if($scope.isFlatFive){
								$scope.tabFiveController = "WarningApprovalResultCtrl";
								$scope.tabResults.push(pageFive);
								$scope.isNumFive = 4;
							}
						}
					}
				}
			}
		}
	   $scope.backWarning = function(){
        	$state.go("warning.warningList");
        }
	}]);
})();